package com.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.dao.TLiuyanbanDAO;
import com.model.TLiuyanban;
import com.model.TUser;
import com.opensymphony.xwork2.ActionSupport;

public class liuyanbanAction extends ActionSupport
{
	private Integer id;
	private String neirong;
	private String liuyanshi;
	private Integer userId;

	private String huifu;
	private String huifushi;
	
	private TLiuyanbanDAO liuyanbanDAO;
	
	public String liuyanbanAdd()
	{
		HttpServletRequest request=ServletActionContext.getRequest();
		HttpSession session=request.getSession();
		TUser user=(TUser)session.getAttribute("user");
		
		TLiuyanban liuyanban=new TLiuyanban();
		
		//liuyanban.setId(id);
		liuyanban.setNeirong(neirong);
		liuyanban.setLiuyanshi(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
		liuyanban.setUserId(user.getUserId());
		
		liuyanban.setHuifu("");
		liuyanban.setHuifushi("");
		liuyanbanDAO.save(liuyanban);
		
		request.setAttribute("msg", "�������");
		return "msg";
	}
	
	
	public String liuyanbanMana()
	{
		String sql="from TLiuyanban order by liuyanshi desc";
		List liuyanbanList=liuyanbanDAO.getHibernateTemplate().find(sql);
		
		Map request=(Map)ServletActionContext.getContext().get("request");
		request.put("liuyanbanList", liuyanbanList);
		return ActionSupport.SUCCESS;
	}
	
	
	public String liuyanbanDel()
	{
		TLiuyanban liuyanban=liuyanbanDAO.findById(id);
		liuyanbanDAO.delete(liuyanban);
		
		HttpServletRequest request=ServletActionContext.getRequest();
		request.setAttribute("msg", "删除成功");
		return "msg";
	}
	
	
	public String liuyanbanHuifu()
	{
		TLiuyanban liuyanban=liuyanbanDAO.findById(id);
		liuyanban.setHuifu(huifu);
		liuyanban.setHuifushi(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
		
		liuyanbanDAO.attachDirty(liuyanban);
		 	
		HttpServletRequest request=ServletActionContext.getRequest();
		request.setAttribute("msg", "回复成功");
		return "msg";
	}
	
	
	public String liuyanbanDetail()
	{
		TLiuyanban liuyanban=liuyanbanDAO.findById(id);
		HttpServletRequest request=ServletActionContext.getRequest();
		request.setAttribute("liuyanban", liuyanban);
		return ActionSupport.SUCCESS;
	}
	
	
	
	public String liuyanbanAll()
	{
		String sql="from TLiuyanban order by liuyanshi desc";
		List liuyanbanList=liuyanbanDAO.getHibernateTemplate().find(sql);
		
		for(int i=0;i<liuyanbanList.size();i++)
		{
			TLiuyanban liuyanban=(TLiuyanban)liuyanbanList.get(i);
		}
		
		Map request=(Map)ServletActionContext.getContext().get("request");
		request.put("liuyanbanList", liuyanbanList);
		return ActionSupport.SUCCESS;
	}


	public Integer getId() {
		return id;
	}


	public void setId(Integer id) {
		this.id = id;
	}


	public String getNeirong() {
		return neirong;
	}


	public void setNeirong(String neirong) {
		this.neirong = neirong;
	}


	public String getLiuyanshi() {
		return liuyanshi;
	}


	public void setLiuyanshi(String liuyanshi) {
		this.liuyanshi = liuyanshi;
	}


	public Integer getUserId() {
		return userId;
	}


	public void setUserId(Integer userId) {
		this.userId = userId;
	}


	public String getHuifu() {
		return huifu;
	}


	public void setHuifu(String huifu) {
		this.huifu = huifu;
	}


	public String getHuifushi() {
		return huifushi;
	}


	public void setHuifushi(String huifushi) {
		this.huifushi = huifushi;
	}


	public TLiuyanbanDAO getLiuyanbanDAO() {
		return liuyanbanDAO;
	}


	public void setLiuyanbanDAO(TLiuyanbanDAO liuyanbanDAO) {
		this.liuyanbanDAO = liuyanbanDAO;
	}

}
